package com.jrtc.service.impl;

import com.jrtc.base.entity.bo.CatchBallRecord;
import com.jrtc.base.entity.bo.CatchBallRecordDetails;
import com.jrtc.base.entity.bo.Patient;
import com.jrtc.base.entity.bo.PatientInvestigation;
import com.jrtc.base.entity.vo.CatchBallRecordVo;
import com.jrtc.base.entity.vo.PatientInvestigationVo;
import com.jrtc.base.util.IdUtils;
import com.jrtc.dao.CatchBallRecordDao;
import com.jrtc.dao.CatchBallRecordDetailsDao;
import com.jrtc.dao.PatientDao;
import com.jrtc.dao.PatientInvestigationDao;
import com.jrtc.service.CatchBallRecordService;
import com.jrtc.service.PatientInvestigationService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

@Service("patientInvestigationService")
public class PatientInvestigationServiceImpl implements PatientInvestigationService {
    @Resource
    private PatientInvestigationDao patientInvestigationDao;

    /**
     * 添加患者问卷记录
     * */
    @Override
    public int investigation(PatientInvestigationVo patientInvestigationVo) throws Exception {
        if (patientInvestigationVo.getPatientInvestigationList() != null &&
                patientInvestigationVo.getPatientInvestigationList().size() > 0){

            IdUtils idUtils = new IdUtils();
            String answerNum = idUtils.randomUUID();

            for (PatientInvestigation patientInvestigation : patientInvestigationVo.getPatientInvestigationList()) {
                patientInvestigation.setPatientId(patientInvestigationVo.getPatientId());
                patientInvestigation.setQuestionNaireId(patientInvestigationVo.getQuestionNaireId());
                patientInvestigation.setScore(patientInvestigationVo.getScore());
                patientInvestigation.setAnswerTime(new Date());
                patientInvestigation.setAnswerNum(answerNum);
                int investigation = patientInvestigationDao.investigation(patientInvestigation);
                if (investigation <= 0){
                    throw new Exception("添加患者问卷记录失败，失败问题：" + patientInvestigation.getPatientId() + ",失败答案：" + patientInvestigation.getAnswerId());
                }
            }
        }
        else {
            throw new Exception("缺少必要参数");
        }
        return 1;
    }
}